{% extends "base_generic.html" %}

{% block content %}

  {% if form.errors %}
    <div class="alert alert-danger">
      <p>用户名或密码不正确，请重试。</p>
    </div>
  {% endif %}

  {% if next %}
    {% if user.is_authenticated %}
      <div class="alert alert-warning">
        <p>您的账号没有访问此页面的权限。请使用其他账号登录。</p>
      </div>
    {% else %}
      <div class="alert alert-info">
        <p>请登录后查看此页面。</p>
      </div>
    {% endif %}
  {% endif %}

  <div class="row justify-content-center">
    <div class="col-md-6">
      <div class="card">
        <div class="card-header">
          <h3 class="text-center">用户登录</h3>
        </div>
        <div class="card-body">
          <form method="post" action="{% url 'login' %}">
            {% csrf_token %}
            <div class="mb-3">
              <label for="id_username" class="form-label">用户名</label>
              <input type="text" name="username" id="id_username" class="form-control" required>
            </div>
            <div class="mb-3">
              <label for="id_password" class="form-label">密码</label>
              <input type="password" name="password" id="id_password" class="form-control" required>
            </div>
            <div class="d-grid gap-2">
              <button type="submit" class="btn btn-primary">登录</button>
            </div>
            <input type="hidden" name="next" value="{{ next }}">
          </form>
        </div>
        <div class="card-footer text-center">
          <p><a href="{% url 'password_reset' %}">忘记密码?</a></p>
        </div>
      </div>
    </div>
  </div>

{% endblock %} 